import { Controller, Get, Post, Body, Patch, Param, Delete, Inject } from '@nestjs/common';
import { ProvideTestService } from './provide-test.service';
import { CreateProvideTestDto } from './dto/create-provide-test.dto';
import { UpdateProvideTestDto } from './dto/update-provide-test.dto';

interface factoryData {
  name: string
}

@Controller('provide-test')
export class ProvideTestController {
  // custom自定义的Provide
  constructor(private readonly provideTestService: ProvideTestService,
    @Inject('custom') private readonly custom: any,
    @Inject('factory') private readonly factory1: factoryData,
    @Inject('factory2') private readonly factory2: any
  ) { }

  @Get()
  async findAll() {
    console.log('custom--', this.custom.name);
    const data = await this.factory2
    return this.factory1.name + data
    // return this.provideTestService.findAll();
  }

  @Get('/getAll')
  async getAll() {

    return this.provideTestService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.provideTestService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateProvideTestDto: UpdateProvideTestDto) {
    return this.provideTestService.update(+id, updateProvideTestDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.provideTestService.remove(+id);
  }
}
